/*
 * @Author: SamZhang samzhang@apjcorp.com
 * @Date: 2022-12-02 10:14:44
 * @LastEditors: SamZhang samzhang@apjcorp.com
 * @LastEditTime: 2023-02-16 15:51:58
 * @FilePath: /circulation-web/src/components/__tests__/SitewideSettings-test.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { expect } from "chai";
import { stub } from "sinon";

import * as React from "react";
import { mount } from "enzyme";

import { SitewideSettings } from "../SitewideSettings";

const applocation_root = localStorage.getItem("MOBEBR_CONFIG_APPLICATION_ROOT");

describe("SitewideSettings", () => {
  let wrapper;
  let fetchData;
  let editItem;
  const data = {
    settings: [{ key: "test key", value: "test value" }],
    all_settings: [{ key: "test key", label: "test label" }],
  };

  const pause = () => {
    return new Promise<void>((resolve) => setTimeout(resolve, 0));
  };

  beforeEach(() => {
    fetchData = stub();
    editItem = stub().returns(
      new Promise<void>((resolve) => resolve())
    );

    wrapper = mount(
      <SitewideSettings
        data={data}
        fetchData={fetchData}
        editItem={editItem}
        csrfToken="token"
        isFetching={false}
      />
    );
  });

  it("shows sitewide setting list", () => {
    const sitewideSetting = wrapper.find("li");
    expect(sitewideSetting.length).to.equal(1);
    expect(sitewideSetting.at(0).text()).to.contain("test label");
    const editLink = sitewideSetting.at(0).find("a").at(0);
    expect(editLink.props().href).to.equal(
      applocation_root + "/admin/web/config/sitewideSettings/edit/test key"
    );
  });
});
